exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

/**
 * 多级字典表控制器
 */
class MdictController extends think.BaseController {
  /**
     * 根据搜索条件查询字典列表
     */
  queryDictBySeachAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const data = _this.post('tree_name,status');
      const DictService = _this.service('sys/MdictService');
      const list = yield DictService.queryDictBySeach(data);
      if (list && list.error) {
        return _this.errorJson(list.error);
      } else {
        return _this.successJson(list);
      }
    })();
  }

  /**
     * 查询字典列表
     */
  queryDictListAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const DictService = _this2.service('sys/MdictService');
      const list = yield DictService.queryDictList();
      return _this2.successJson(list);
      if (list && list.error) {
        return _this2.errorJson(list.error);
      } else {
        return _this2.successJson(list);
      }
    })();
  }

  /**
     * 保存字典
     */
  saveMDictAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const data = _this3.post('parent_id,tree_name,sort,description,remarks');
      const DictService = _this3.service('sys/MdictService');
      data.create_by = data.update_by = _this3.getUser().userId;
      const res = yield DictService.saveMDict(data);
      if (res && res.error) {
        return _this3.errorJson(res.error);
      } else {
        return _this3.successJson(res);
      }
    })();
  }

  /**
     * 修改字典
     */
  updateMDictAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const data = _this4.post('id,parent_id,tree_name,sort,description,remarks');
      data.update_by = _this4.getUser().userId;
      const DictService = _this4.service('sys/MdictService');
      const res = yield DictService.updateMDict(data);
      if (res && res.error) {
        return _this4.errorJson(res.error);
      } else {
        return _this4.successJson(res);
      }
    })();
  }

  /**
     * 删除多级字典
     */
  deleteMDictAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const id = _this5.post('id');
      const MDictService = _this5.service('sys/MdictService');
      const res = yield MDictService.deleteMDict(id);
      if (res && res.error) {
        return _this5.errorJson(res.error);
      } else {
        return _this5.successJson(res);
      }
    })();
  }

  /**
     * 修改多级字典状态
     */
  updateDictStatusAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      const id = _this6.post('id');
      const status = _this6.post('status');
      const MDictService = _this6.service('sys/MdictService');
      const res = yield MDictService.updateDictStatus(id, status);
      if (res && res.error) {
        return _this6.errorJson(res.error);
      } else {
        return _this6.successJson(res);
      }
    })();
  }
}
exports.default = MdictController;